package com.ddstation.appeal.controller;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ddstation.appeal.service.AppealService;
import com.ddstation.crm.login.bean.SessionLoginData;
import com.ddstation.crud.entity.DtInvsIllegalAppealEntity;

@Controller @Lazy
public class AppealController {
	
	/**
	 * 申诉更新接口
	 * 
	 * @param DtInvsIllegalAppealEntity  页面输入的条件
	 * 
	 * @return
	 * @throws ParseException 
	 */
	@RequestMapping(value="invs_appeal.do/update", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> updateInvsAppealEvent(
			@RequestBody DtInvsIllegalAppealEntity _in,
			HttpSession session){

		Map<String, Object> ret = new HashMap<String, Object>();
		ret.put("errcode", -1);
		ret.put("errMsg", "系统出错，请稍后再试！");
		
		SessionLoginData loginData = (SessionLoginData)session.getAttribute(SessionLoginData.KEY );
		// 访问权限check(防止异常调用)
//		if ( !sewageService.checkAccessAuthority(loginData.getInstitution().getId(),_in.getInstitutionId()) ){
//			ret.put("errMsg", "没有访问权限！");
//			return ret;
//		}
		if (_in.getIllegalId() == null){
			ret.put("errMsg", "入参不足，illegalId为null");
			return ret;
		}
        // 查询实施
		_in.setSupervisorId(loginData.getDoctor().getSupervisorId());
		_in.setFeedbackTm(new Date());
		appealService.updateAppealAndCheck(_in);

		ret.put("errcode", 0);
		ret.put("errMsg", "");

		return ret;
	}

	
	@Inject private AppealService appealService;
}
